import Vue from 'vue'
import App from '../../App'

let apiurl = ''; //测试
if (process.env.NODE_ENV === 'development') {
	apiurl = 'https://crmtest.jxyl.com/api/'; //测试
} else {
	apiurl = 'https://crm.jxyl.com/api/'; //测试
}

// // 普通无需登录信息
const mxp_api = (url, method, data, show) => {
	return new Promise((resolve, reject) => {
		// if(show){
		// 	uni.showLoading({
		// 		title:'加载中...',
		// 	})
		// }
		if (url.indexOf('api-shop-member') > -1) {
			apiurl = 'https://vip.jxyl.com/api/'
		} else {
			apiurl = 'https://crm.jxyl.com/api/'
		}
		uni.request({
			url: apiurl + url,
			method: method,
			data: data,
			header: {
				'content-type': 'application/json',
				// 'qywxUserInfo': uni.getStorageSync('qywxUserInfo')
			},
			success: (res) => {
				if (res.statusCode === 502 && res.statusCode) {
					uni.showToast({
						title: '服务器内部错误',
						duration: 1000,
						icon: "none"
					});
					return
				}
				resolve(res.data)
				// if(show){
				// 	uni.hideLoading();
				// }
			},
			fail: (err) => {
				reject(err.data)
			},
			complete: (statusCode) => {
				if (statusCode.statusCode === 502) {
					uni.showToast({
						title: '服务器内部错误',
						duration: 1000,
						icon: "none"
					});
					return
				}
			}
		});
	})
}
Vue.prototype.$Api = {
	mxp_api
};
